{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb7978b8-2586-4567-8c14-1042b2db5e4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from mpl_toolkits.basemap import Basemap\n",
    "import matplotlib.pyplot as plt\n",
    "map_1 = Basemap()\n",
    "map_1.drawcoastlines()\n",
    "plt.show()\n",
    "plt.savefig('/第9章/data/test.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b964777-4849-4889-8f3a-eac248375f93",
   "metadata": {},
   "outputs": [],
   "source": [
    "pip install mpl_toolkits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08bd9bae-f179-43f2-83e9-a60a8669e808",
   "metadata": {},
   "outputs": [],
   "source": [
    "pip install numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46e6a11d-d0c6-4cc9-93ac-0c649ce6a715",
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "\"\"\"\n",
    "Created on Fri Oct 22 16:32:43 2021\n",
    "\n",
    "@author: lx\n",
    "\"\"\"\n",
    "import jieba\n",
    "text = \"国庆期间去广州看了小蛮腰，希望有机会登上塔顶。\"\n",
    "seg = jieba.cut(text,cut_all=False)\n",
    "print('精确模式：'+'/'.join(seg))\n",
    "seg = jieba.lcut(text,cut_all=False)\n",
    "print(seg)\n",
    "seg = jieba.cut(text,cut_all=True)\n",
    "print('全模式：'+'/'.join(seg))\n",
    "seg = jieba.lcut(text,cut_all=True)\n",
    "print(seg)\n",
    "seg = jieba.cut_for_search(text)\n",
    "print('搜索引擎模式：'+'/'.join(seg))\n",
    "seg = jieba.lcut_for_search(text)\n",
    "print(seg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02b89f3a-7a38-4c17-a281-23a84f236d7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "\"\"\"\n",
    "Created on Fri Oct 22 16:41:39 2021\n",
    "\n",
    "@author: lx\n",
    "\"\"\"\n",
    "from collections import Counter\n",
    "content=open(r'C:/case/content.txt',encoding='utf-8').read()\n",
    "print(Counter(content).most_common(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a44e368e-a804-4f30-ac2a-8b62fad5a566",
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "\"\"\"\n",
    "Created on Fri Oct 22 16:41:39 2021\n",
    "\n",
    "@author: lx\n",
    "\"\"\"\n",
    "from collections import Counter\n",
    "content=open(r'../data/content.txt',encoding='utf-8').read()\n",
    "print(Counter(content).most_common(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2a4a9b2-ff0b-4633-9a4d-0ffafbdcdf27",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79ccc775-958b-470c-83fb-8a59b096ebbf",
   "metadata": {},
   "outputs": [],
   "source": [
    "pip install pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7993cbf1-abca-488d-b133-9244b6a3d88e",
   "metadata": {},
   "outputs": [],
   "source": [
    "pip install matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4126b12a-467b-4deb-8c9d-20177cf79f8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/bin/bash: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8)\n",
      "Collecting geopandas\n",
      "  Using cached geopandas-1.0.1-py3-none-any.whl.metadata (2.2 kB)\n",
      "Requirement already satisfied: numpy>=1.22 in /opt/conda/lib/python3.11/site-packages (from geopandas) (2.0.0)\n",
      "Collecting pyogrio>=0.7.2 (from geopandas)\n",
      "  Using cached pyogrio-0.9.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.8 kB)\n",
      "Requirement already satisfied: packaging in /opt/conda/lib/python3.11/site-packages (from geopandas) (24.0)\n",
      "Requirement already satisfied: pandas>=1.4.0 in /opt/conda/lib/python3.11/site-packages (from geopandas) (2.2.2)\n",
      "Collecting pyproj>=3.3.0 (from geopandas)\n",
      "  Downloading pyproj-3.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (31 kB)\n",
      "INFO: pip is looking at multiple versions of geopandas to determine which version is compatible with other requirements. This could take a while.\n",
      "Collecting geopandas\n",
      "  Downloading geopandas-1.0.0-py3-none-any.whl.metadata (2.2 kB)\n",
      "  Downloading geopandas-0.14.4-py3-none-any.whl.metadata (1.5 kB)\n",
      "Collecting fiona>=1.8.21 (from geopandas)\n",
      "  Downloading fiona-1.9.6-cp311-cp311-manylinux2014_x86_64.whl.metadata (50 kB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.2/50.2 kB\u001b[0m \u001b[31m7.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:02\u001b[0mm\n",
      "\u001b[?25hCollecting geopandas\n",
      "  Downloading geopandas-0.14.3-py3-none-any.whl.metadata (1.5 kB)\n",
      "  Downloading geopandas-0.14.2-py3-none-any.whl.metadata (1.5 kB)\n",
      "  Downloading geopandas-0.14.1-py3-none-any.whl.metadata (1.5 kB)\n",
      "  Downloading geopandas-0.14.0-py3-none-any.whl.metadata (1.5 kB)\n",
      "  Downloading geopandas-0.13.2-py3-none-any.whl.metadata (1.5 kB)\n",
      "INFO: pip is still looking at multiple versions of geopandas to determine which version is compatible with other requirements. This could take a while.\n",
      "  Downloading geopandas-0.13.1-py3-none-any.whl.metadata (1.5 kB)\n",
      "  Downloading geopandas-0.13.0-py3-none-any.whl.metadata (1.5 kB)\n",
      "  Downloading geopandas-0.12.2-py3-none-any.whl.metadata (1.0 kB)\n",
      "  Downloading geopandas-0.12.1-py3-none-any.whl.metadata (1.0 kB)\n",
      "  Downloading geopandas-0.12.0-py3-none-any.whl.metadata (1.0 kB)\n",
      "INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. See https://pip.pypa.io/warnings/backtracking for guidance. If you want to abort this run, press Ctrl + C.\n",
      "  Downloading geopandas-0.11.1-py3-none-any.whl.metadata (1.0 kB)\n",
      "  Downloading geopandas-0.11.0-py3-none-any.whl.metadata (1.0 kB)\n",
      "  Downloading geopandas-0.10.2-py2.py3-none-any.whl.metadata (935 bytes)\n",
      "  Downloading geopandas-0.10.1-py2.py3-none-any.whl.metadata (935 bytes)\n",
      "  Downloading geopandas-0.10.0-py2.py3-none-any.whl.metadata (935 bytes)\n",
      "  Downloading geopandas-0.9.0-py2.py3-none-any.whl.metadata (908 bytes)\n",
      "  Downloading geopandas-0.8.2-py2.py3-none-any.whl.metadata (892 bytes)\n",
      "  Downloading geopandas-0.8.1-py2.py3-none-any.whl.metadata (892 bytes)\n",
      "  Downloading geopandas-0.8.0-py2.py3-none-any.whl.metadata (892 bytes)\n",
      "  Downloading geopandas-0.7.0-py2.py3-none-any.whl.metadata (892 bytes)\n",
      "  Downloading geopandas-0.6.3-py2.py3-none-any.whl.metadata (859 bytes)\n",
      "  Downloading geopandas-0.6.2-py2.py3-none-any.whl.metadata (859 bytes)\n",
      "  Downloading geopandas-0.6.1-py2.py3-none-any.whl.metadata (859 bytes)\n",
      "  Downloading geopandas-0.6.0-py2.py3-none-any.whl.metadata (859 bytes)\n",
      "  Downloading geopandas-0.5.1-py2.py3-none-any.whl.metadata (848 bytes)\n",
      "  Downloading geopandas-0.5.0-py2.py3-none-any.whl.metadata (848 bytes)\n",
      "  Downloading geopandas-0.4.1-py2.py3-none-any.whl.metadata (842 bytes)\n",
      "  Downloading geopandas-0.4.0-py2.py3-none-any.whl.metadata (842 bytes)\n",
      "  Downloading geopandas-0.3.0-py2.py3-none-any.whl.metadata (867 bytes)\n",
      "Collecting descartes (from geopandas)\n",
      "  Downloading descartes-1.1.0-py3-none-any.whl.metadata (2.4 kB)\n",
      "Collecting geopandas\n",
      "  Downloading geopandas-0.2.1-py2.py3-none-any.whl.metadata (867 bytes)\n",
      "  Downloading geopandas-0.2.tar.gz (212 kB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m212.9/212.9 kB\u001b[0m \u001b[31m6.9 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:02\u001b[0m\n",
      "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25ldone\n",
      "\u001b[?25hDiscarding \u001b[4;34mhttps://files.pythonhosted.org/packages/2a/1e/ea0c9ed982a62d693cbebda0da10321361a88d2a44c67292f64ca3675275/geopandas-0.2.tar.gz (from https://pypi.org/simple/geopandas/)\u001b[0m: \u001b[33mRequested geopandas from https://files.pythonhosted.org/packages/2a/1e/ea0c9ed982a62d693cbebda0da10321361a88d2a44c67292f64ca3675275/geopandas-0.2.tar.gz has inconsistent version: expected '0.2', but metadata has '0+unknown'\u001b[0m\n",
      "  Downloading geopandas-0.1.1.tar.gz (15 kB)\n",
      "  Preparing metadata (setup.py) ... \u001b[?25ldone\n",
      "\u001b[?25h  Downloading geopandas-0.1.0.tar.gz (15 kB)\n",
      "  Preparing metadata (setup.py) ... \u001b[?25ldone\n",
      "\u001b[31mERROR: Cannot install geopandas==0.1.0, geopandas==0.1.1, geopandas==0.10.0, geopandas==0.10.1, geopandas==0.10.2, geopandas==0.11.0, geopandas==0.11.1, geopandas==0.12.0, geopandas==0.12.1, geopandas==0.12.2, geopandas==0.13.0, geopandas==0.13.1, geopandas==0.13.2, geopandas==0.14.0, geopandas==0.14.1, geopandas==0.14.2, geopandas==0.14.3, geopandas==0.14.4, geopandas==0.2.1, geopandas==0.3.0, geopandas==0.4.0, geopandas==0.4.1, geopandas==0.5.0, geopandas==0.5.1, geopandas==0.6.0, geopandas==0.6.1, geopandas==0.6.2, geopandas==0.6.3, geopandas==0.7.0, geopandas==0.8.0, geopandas==0.8.1, geopandas==0.8.2, geopandas==0.9.0, geopandas==1.0.0 and geopandas==1.0.1 because these package versions have conflicting dependencies.\u001b[0m\u001b[31m\n",
      "\u001b[0m\u001b[?25h\n",
      "The conflict is caused by:\n",
      "    geopandas 1.0.1 depends on shapely>=2.0.0\n",
      "    geopandas 1.0.0 depends on shapely>=2.0.0\n",
      "    geopandas 0.14.4 depends on shapely>=1.8.0\n",
      "    geopandas 0.14.3 depends on shapely>=1.8.0\n",
      "    geopandas 0.14.2 depends on shapely>=1.8.0\n",
      "    geopandas 0.14.1 depends on shapely>=1.8.0\n",
      "    geopandas 0.14.0 depends on shapely>=1.8.0\n",
      "    geopandas 0.13.2 depends on shapely>=1.7.1\n",
      "    geopandas 0.13.1 depends on shapely>=1.7.1\n",
      "    geopandas 0.13.0 depends on shapely>=1.7.1\n",
      "    geopandas 0.12.2 depends on shapely>=1.7\n",
      "    geopandas 0.12.1 depends on shapely>=1.7\n",
      "    geopandas 0.12.0 depends on shapely<2 and >=1.7\n",
      "    geopandas 0.11.1 depends on shapely<2 and >=1.7\n",
      "    geopandas 0.11.0 depends on shapely<2 and >=1.7\n",
      "    geopandas 0.10.2 depends on shapely>=1.6\n",
      "    geopandas 0.10.1 depends on shapely>=1.6\n",
      "    geopandas 0.10.0 depends on shapely>=1.6\n",
      "    geopandas 0.9.0 depends on shapely>=1.6\n",
      "    geopandas 0.8.2 depends on shapely\n",
      "    geopandas 0.8.1 depends on shapely\n",
      "    geopandas 0.8.0 depends on shapely\n",
      "    geopandas 0.7.0 depends on shapely\n",
      "    geopandas 0.6.3 depends on shapely\n",
      "    geopandas 0.6.2 depends on shapely\n",
      "    geopandas 0.6.1 depends on shapely\n",
      "    geopandas 0.6.0 depends on shapely\n",
      "    geopandas 0.5.1 depends on shapely\n",
      "    geopandas 0.5.0 depends on shapely\n",
      "    geopandas 0.4.1 depends on shapely\n",
      "    geopandas 0.4.0 depends on shapely\n",
      "    geopandas 0.3.0 depends on shapely\n",
      "    geopandas 0.2.1 depends on shapely\n",
      "    geopandas 0.1.1 depends on shapely\n",
      "    geopandas 0.1.0 depends on shapely\n",
      "\n",
      "To fix this you could try to:\n",
      "1. loosen the range of package versions you've specified\n",
      "2. remove package versions to allow pip attempt to solve the dependency conflict\n",
      "\n",
      "\u001b[31mERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts\u001b[0m\u001b[31m\n",
      "\u001b[0mNote: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install geopandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6569add3-940c-4c08-812b-d6e4bad8d8c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import geopandas as gpd\n",
    "import pandas as pd\n",
    "from plotnine import *\n",
    "\n",
    "df_map = gpd.GeoDataFrame.from_file('Virtual_Map1.shp')\n",
    "df_city = pd.read_csv(\"Virtual_City.csv\")\n",
    "\n",
    "df = pd.merge(right=df_map, left=df_city, how='right', on=\"country\")\n",
    "df = gpd.GeoDataFrame(df)\n",
    "\n",
    "# 数值映射到单个视觉通道（气泡大小）\n",
    "\n",
    "base_plot = (ggplot(df) +\n",
    "             geom_map(fill='white', color='gray') +\n",
    "             geom_point(aes(x='long', y='lat', size='orange'), shape='o', colour=\"black\", fill='#EF5439') +\n",
    "             geom_text(aes(x='long', y='lat', label='city'), colour=\"black\", size=10, nudge_y=-1.5) +\n",
    "             scale_size(range=(2, 9), name='price')\n",
    "             )\n",
    "print(base_plot)\n",
    "#数值映射到两个视觉通道（气泡大小和颜色）\n",
    "\n",
    "base_plot=(ggplot(df)+\n",
    "           geom_map(fill='white',color='gray')+\n",
    "           geom_point(aes(x='long', y='lat',size='orange',fill='orange'),shape='o',colour=\"black\")+\n",
    "           geom_text(aes(x='long', y='lat', label='city'),colour=\"black\",size=10,nudge_y=-1.5)+\n",
    "          scale_fill_cmap(name=\"YlOrRd\")+\n",
    "          scale_size(range=(2,9),name='price')\n",
    ")\n",
    "print(base_plot)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99e40376-ecf2-4e79-a84d-eb4a142f1ee4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
